<template>
   <div class="produce-in-table-wrap">
    <el-table
      :data="tableData"
      style="width: 100%"
      :border="true"
      :fit="true"
      size="mini"
      align="center"
      :row-class-name="tableDate">
      <el-table-column
        prop="id"
        label="id"
        min-width="70"
        align="center">
      </el-table-column>

      <el-table-column
        prop="order"
        label="订单号"
        min-width="150"
        align="center">
      </el-table-column>

      <el-table-column
        prop="created_at"
        label="下单时间"
        min-width="150"
        align="center">
      </el-table-column>

      <el-table-column
        prop="nickname"
        label="客户名称"
        min-width="120"
        align="center">
      </el-table-column>

      <el-table-column
        prop="all_price"
        label="金额"
        min-width="120"
        align="center">
      </el-table-column>

      <el-table-column
        prop="goods_count"
        label="商品数量"
        min-width="120"
        align="center">
      </el-table-column>

      <el-table-column
        prop="status"
        label="状态"
        min-width="90"
        align="center">
      </el-table-column>

      <el-table-column label="操作"
      min-width="210"
      align="center">
        <template slot-scope="scope">
          
          <template v-if="scope.row.status==='待下单'">
            <el-button
              size="mini"
              plain
              type="success"
              @click="ckeck(scope.row)">审核</el-button>
            <el-button
              size="mini"
              plain
              type="primary"
              @click="edit(scope.row)">编辑</el-button>
            <el-button
              size="mini"
              plain
              type="danger"
              @click="del(scope.row)">删除</el-button>
          </template>

          <template v-if="scope.row.status==='配料中'||scope.row.status==='生产中'||scope.row.status==='生产完'">
            <el-button
              size="mini"
              plain
              type="success"
              @click="ckeck(scope.row)">查看详情</el-button>
            <el-button
              size="mini"
              plain
              type="primary"
              @click="toProductList(scope.row)">查看生产单</el-button>
          </template>

          <template v-if="scope.row.status==='已入库'">
            <el-button
              size="mini"
              plain
              type="warning"
              @click="chuhuo(scope.row)">出货</el-button>
            <el-button
              size="mini"
              plain
              type="primary"
              @click="toProductList(scope.row)">查看生产单</el-button>
          </template>

          <template v-if="scope.row.status==='已出货'||scope.row.status==='已作废'">
            <el-button
              size="mini"
              plain
              type="primary"
              @click="ckeck(scope.row)">查看详情</el-button>
          </template>

        </template>
      </el-table-column>
    </el-table>
    <deleteConfirm v-if="showMask" @closeDelete="closeDelete" @deleteConfirm="deleteConfirm"></deleteConfirm>
  </div>
</template>
<script lang="ts">
import Vue from 'vue';
import Component from 'vue-class-component';
import { Prop, Emit } from 'vue-property-decorator';
import ajaxResquest from '@/api/apiRequest';
import deleteConfirm from '@/components/deleteConfirm.vue';

@Component({
  components: {
    deleteConfirm
  }
})
export default class ProduceInTable extends Vue {
  @Prop({
    type: Array
  })
  tableData!: any[];
  showMask: boolean = false;
  deleteRes!: ajaxResquest;
  chuhuoRes!: ajaxResquest;
  deleteId!: number;
  mounted() {
    this.deleteRes = new ajaxResquest('/order/delOrder');
    this.chuhuoRes = new ajaxResquest('/order/orderOutToDo');
  }
  tableDate({ row, rowIndex }: any) {
    if (row.colour === 'red') {
      return 'warning-row';
    }
  }
  ckeck(row: any) {
    console.log(row);
    this.$to('orderStatusCheck', { id: row.id, status: row.status });
  }
  del(row: any) {
    this.deleteId = row.id;
    this.showMask = true;
  }
  closeDelete() {
    this.showMask = false;
  }
  edit(row: any) {
    this.$to('orderCreate', { id: row.id, edit: true });
  }
  deleteConfirm() {
    this.deleteRes
      .getFunction({ orderInfoId: this.deleteId })
      .then((res: any) => {
        if (res.data.code === 1) {
          this.showMask = false;
        }
        this.getData();
      });
  }
  chuhuo(row: any) {
    // this.chuhuoRes.getFunction()
    this.$to('daichuhuo', { id: row.id });
  }
  toProductList(row: any) {
    this.$to('productList', { search: true, id: row.id });
  }
  @Emit('getData')
  getData() {}
}
</script>
<style lang="less">
</style>
